package redis

import (
	redis2 "content_system/infra/redis"
	util2 "content_system/util"
	"context"
	"time"
)

func SetUserSessionID(ctx context.Context, sessionID string, userID int64) error {
	key := util2.GetUserSessionIDKey(sessionID)
	err := redis2.SetWithExpire(ctx, key, util2.Int64ToString(userID), time.Hour*12)
	if err != nil {
		return err
	}
	return nil
}

func GetUserIDBySessionID(ctx context.Context, sessionID string) (int64, error) {
	key := util2.GetUserSessionIDKey(sessionID)
	uid, err := redis2.Get(ctx, key)
	if err != nil {
		return 0, err
	}
	return util2.StringToInt64(uid), nil
}
